<template>
    <div class="app-container">
        <el-row :gutter="20">
            <el-col :span="4" :xs="24">

              <fileTrees @handleNodeClick="onTreeClick" :isRefresh="isRefresh" :isnoClick="isnoClick" :source="1"></fileTrees>

            </el-col>
            <el-col :span="20" :xs="24">

                <el-row :gutter="10" class="mb8" ref="refbut">
                    <el-col :span="1.5" v-show="isShowTree">
                        <el-button type="primary" plain icon="el-icon-plus"  @click="treehandleAdd">添加树节点</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="isShowGeneralarchive">
                        <el-button type="primary" plain icon="el-icon-plus"  @click="generalArchiveAdd">添加全宗节点</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="isShowCategory">
                        <el-button type="primary" plain icon="el-icon-plus"  @click="categoryAdd">添加门类节点</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="isShowClassification">
                        <el-button type="primary" plain icon="el-icon-plus"  @click="classificationAdd">添加分类节点</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="isShowEmpty">
                        <el-button type="primary" plain icon="el-icon-plus"  @click="emptyAdd">添加空节点</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="isShowLevel">
                        <el-button type="primary" plain icon="el-icon-plus"  @click="levelAdd">添加层级</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="isShowUpdate">
                        <el-button type="success" plain icon="el-icon-edit"  @click="handleUpdate">修改节点</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="isShowDelete">
                        <el-button type="danger" plain icon="el-icon-delete"  @click="handleDelete">删除节点</el-button>
                    </el-col>
                </el-row>
                <el-table v-loading="loading" :data="DataList" :height="tableHeight" v-show="isShowTable">
                  <el-table-column label="节点名称" prop="name" align="center" />
                  <el-table-column label="节点类型" prop="type" align="center" />
                  <el-table-column label="分类值" prop="propertyValue" align="center" />
                </el-table>
                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getList" />
            </el-col>
        </el-row>

        <!-- 树节点添加及各节点修改 -->
        <el-dialog :title="dialog.title0" :visible.sync="dialog.open0" width="30%" append-to-body>
             <div>
                <el-form ref="form" :rules="rules" :model="form" label-width="80px">
                    <el-form-item label="节点名称" prop="codeName">
                        <el-input v-model="form.codeName" placeholder="请输入节点名称"></el-input>
                    </el-form-item>
                    <el-form-item label="排序号" prop="orderNo">
                        <el-input-number v-model="form.orderNo" controls-position="right" style="width: 100%" :min="1" placeholder="请输入排序号"></el-input-number>
                    </el-form-item>
                    <el-form-item label="备注" prop="remark">
                        <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>

        <!-- 全宗节点新增 -->
        <el-dialog :title="generalarchiveTitle" :visible.sync="generalarchiveOpen" width="30%" append-to-body>
            <div>
                <el-checkbox-group v-model="selectedOptions">
                  <el-row>
                    <el-col v-for="option in dataOptions" :key="option.value" :span="24">
                      <el-checkbox :label="option">
                        {{ option.label }}
                      </el-checkbox>
                    </el-col>
                  </el-row>
                </el-checkbox-group>
            </div>
            <div slot="footer" class="dialog-footer">
              <el-button type="primary" @click="submitGeneralarchive">确 定</el-button>
              <el-button @click="generalarchiveOpen = false">取 消</el-button>
            </div>
        </el-dialog>

        <!-- 门类节点新增 -->
        <el-dialog :title="categoryTitle" :visible.sync="categoryOpen" width="30%" append-to-body :before-close="categoryCancel">
          <div style="overflow-y: auto; height: 250px">
            <el-tree ref="categoryTree" :data="treeData" show-checkbox node-key="id" :props="defaultProps" default-expand-all>
            </el-tree>
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitCategory">确 定</el-button>
            <el-button @click="categoryCancel">取 消</el-button>
          </div>
        </el-dialog>

        <!-- 层级节点新增 -->
        <el-dialog :title="LevelTitle" :visible.sync="LevelOpen" width="30%" append-to-body>
          <div>
            <el-checkbox-group v-model="selectOption">
              <el-checkbox v-for="option in LevelOptions" :key="option.value" :label="option" :disabled="option.disabled">
                {{ option.label }}
              </el-checkbox>
            </el-checkbox-group>
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitLevel">确 定</el-button>
            <el-button @click="LevelOpen = false">取 消</el-button>
          </div>
        </el-dialog>

        <!-- 分类节点新增 -->
        <el-dialog :title="ClassificationTitle" :visible.sync="ClassificationOpen" width="30%" append-to-body :before-close="ClassificationCancel">
          <div>
            <label v-for="option in ClassificationOptions" :key="option.id">
              <input type="radio" v-model="selected" :value="option" @change="handleOptionChange">
              {{ option.label }}
            </label>
          </div>
          <div v-show="isShowHr">
            <hr>
            <div v-if="selected.id == 'ND'">
              <el-form ref="ndForm" :rules="ndRules" :model="ndForm" label-width="80px">
                <el-form-item label="开始年度" prop="year">
                  <el-date-picker v-model="ndForm.year" type="year" style="width: 40%" placeholder="请选择开始年度" value-format="yyyy" format="yyyy"></el-date-picker>
                </el-form-item>
                <el-form-item label="连续时间" prop="continuousTime">
                  <el-input-number v-model="ndForm.continuousTime" controls-position="right" style="width: 40%" :min="1" placeholder="请输入连续时间"></el-input-number>
                </el-form-item>
              </el-form>
            </div>
            <div v-else>
              <el-checkbox-group v-model="valueSelected">
                <el-checkbox v-for="option in valueOptions" :key="option.value" :label="option">
                  {{ option.label }}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitClassification">确 定</el-button>
            <el-button @click="ClassificationCancel">取 消</el-button>
          </div>
        </el-dialog>
    </div>
</template>
<script>
import estimateTableHeight from '@/mixins/estimateTableHeight'
import fileTrees from "@/components/fileTrees/index.vue"
import {
  addCode,
  gettrees,
  listCode,
  getCode,
  updateCode,
  getFondsByTenantCode, delCode, getcatebyfondsid, getCateType, getfl, getData
} from "@/api/archive/archiveTreeDefinition.js"
import queryCriteriaList from "@/components/queryCriteriaList";
export default {
    mixins: [estimateTableHeight], // 混入方法
    components: {
      fileTrees
    },
    data() {
        const equalToTime = (rule, value, callback) => {
          if (value) {
            var reg = /^[1-9]\d*$/
            if (reg.test(value) == false) {
              callback(new Error('请输入正整数'))
            } else {
              callback()
            }
          } else {
            callback()
          }
        };
        return {
            //是否刷新树结构
            isRefresh: false,
            isnoClick:true,
            // 遮罩层
            loading: true,
            dialog: {
                title0: "",
                open0: false
            },
            generalarchiveTitle: "全宗节点",
            generalarchiveOpen: false,
            categoryTitle: "门类节点",
            categoryOpen: false,
            LevelTitle: "层级节点",
            LevelOpen: false,
            ClassificationTitle: "分类节点",
            ClassificationOpen: false,
            //添加树节点form表单
            form:{
                type:undefined,//树节点
                parentId:undefined,//父节点
                name:[],//树节点名称
                remark:undefined,//备注
                orderNo:undefined,//排序
                codeName: undefined
            },
            // 表单校验
            rules: {
              codeName: [
                { required: true, message: "请输入节点名称", trigger: "blur" }
              ]
            },
            dataOptions: [], // 后端返回全宗数据
            selectedOptions: [], // 已选中的全宗选项
            LevelOptions: [], // 层级节点数据
            selectOption: [], //已选中的层级选项
            ClassificationOptions: [], // 分类节点数据
            selected: [], //已选中的分类选项
            valueOptions: [], //分类节点数据对应的分类值
            valueSelected: [], //已选中的分类值
            deptOptions: undefined,// 部门树选项
            // 选中的门类树节点
            checkedKeys: [],
            //默认展开的树节点
            expandedkeys: [],
            //默认选中的树节点
            currentNodekey: "",
            // 部门名称
            deptName: undefined,
            defaultProps: {
                children: "children",
                label: "label"
            },
            // 门类树
            treeData: [],
            total: 0,
            queryParams : {
              pageNum: 1,
              pageSize: 10
            },
            DataList: [],
            // 是否显示添加树节点按钮
            isShowTree: false,
            // 是否展示添加全宗节点按钮
            isShowGeneralarchive: false,
            // 是否展示添加门类节点按钮
            isShowCategory: false,
            // 是否展示添加分类节点按钮
            isShowClassification: false,
            // 是否展示添加空节点按钮
            isShowEmpty: false,
            // 是否展示添加层级按钮
            isShowLevel: false,
            // 是否展示修改节点按钮
            isShowUpdate: false,
            // 是否展示删除节点按钮
            isShowDelete: false,
            // 是否展示表格
            isShowTable: false,
            // 是否展示分割线
            isShowHr: false,
            // 层级
            level: null,
            codeType: [
              {value: 't', label: '树节点'},
              {value: 'n', label: '空节点'},
              {value: 'f', label: '全宗节点'},
              {value: 'a', label: '门类节点'},
              {value: 'c', label: '分类节点'},
              {value: 'l', label: '层级节点'},
            ],
            ndForm: {
              year: undefined,
              continuousTime: undefined
            },
            // 表单校验
            ndRules: {
              year: [
                { required: true, message: "请选择开始年度", trigger: "blur" }
              ],
              continuousTime: [
                { required: true, message: "请选择连续时间", trigger: "blur" },
                { required: true, validator: equalToTime, trigger: "blur" }
              ]
            },
        }
    },
    created() {
        this.isShowTable = false
        this.isShowTree = false
        this.isShowGeneralarchive = false
        this.isShowCategory = false
        this.isShowClassification = false
        this.isShowEmpty = false
        this.isShowLevel = false
        this.isShowUpdate = false
        this.isShowDelete = false

    },
    methods: {

        // 单击树节点事件
        onTreeClick(data) {
            // 获取当前节点数据
            console.log(data,"++++++++++")
            this.isnoClick=false;
            // 当前节点
            this.queryParams.nodeId = data.id;
            // 增加节点时的父节点id
            this.queryParams.parentId = data.id;
            // 节点类型
            this.queryParams.type = data.nodeType
            // 节点名称
            this.queryParams.label = data.label
            //  右侧表格展示
            if(this.queryParams.parentId != undefined){
              this.isShowTable = true
            }
            // 新增门类时需要传递的全宗id
            if(data.fondsId != null){
              this.queryParams.fondsId = data.fondsId
            }
            // 新增层级时需要传递门类id
            if(data.categoryId != null){
              this.queryParams.categoryId = data.categoryId
            }

            if(this.queryParams.type == null && this.queryParams.parentId == "0"){
              // 根节点下展示树节点新增按钮
              this.isShowTree = true
              this.isShowUpdate = false
              this.isShowDelete = false
              this.isShowGeneralarchive = false
              this.isShowCategory = false
              this.isShowClassification = false
              this.isShowEmpty = true
              this.isShowLevel = false
            } else {
              this.isShowTree = false
              this.isShowUpdate = true
              this.isShowDelete = true
              // 树节点展示全宗、门类、空节点按钮
              if(this.queryParams.type == "t") {
                this.isShowGeneralarchive = true
                this.isShowCategory = false
                this.isShowEmpty = true
                this.isShowClassification = false
                this.isShowLevel = false
              }
              // 全宗节点展示门类、空节点按钮
              else if(this.queryParams.type == "f") {
                this.isShowGeneralarchive = false
                this.isShowCategory = true
                this.isShowEmpty = true
                this.isShowClassification = false
                this.isShowLevel = false
              }
              // 门类节点展示分类、层级、空节点按钮
              else if(this.queryParams.type == "a") {
                this.isShowGeneralarchive = false
                this.isShowCategory = false
                this.isShowClassification = true
                this.isShowLevel = true
                this.isShowEmpty = true
              }
              // 层级节点展示分类、空节点按钮
              else if(this.queryParams.type == "l"){
                this.isShowGeneralarchive = false
                this.isShowCategory = false
                this.isShowClassification = true
                this.isShowLevel = false
                this.isShowEmpty = true
                if (this.getLastIndexOf(data.sub_table_name) == "F") {  //F 件
                  this.level = 0
                } else if (this.getLastIndexOf(data.sub_table_name) == "V") { //卷
                  this.level = 1
                } else { //项目
                  this.level = 3
                }
              }
              // 分类节点展示层级、空节点按钮
              else if(this.queryParams.type == "c"){
                this.isShowGeneralarchive = false
                this.isShowCategory = false
                this.isShowClassification = true
                this.isShowLevel = true
                this.isShowEmpty = true
              }
            }
            // this.queryParams.type = data.type.toString();
            // this.deptOptionsRow = data;
            // this.deptOptionsSelect(data.type);
            // //复制到
            // this.deptOptionsChildrenList = this.deptOptions[0].children.filter((item) => {
            //     return item.id != data.id
            // })
            this.getList();
        },
        // 获取字符串中最后一个_前面的内容和获取最后一个"_"之后的内容
        getLastIndexOf(sub_table_name) {
          // 获取字符串中最后一个_前面的内容:
          var str = sub_table_name;
          var index = str.lastIndexOf("_");
          var strData = str.substring(0, index);
          //获取最后一个"_"之后的内容
          var index1 = strData.lastIndexOf("_");
          strData = strData.substring(index1 + 1, strData.length);
          return strData;
        },
        // 查询节点表格
        getList() {
          this.loading = true
          listCode(this.queryParams).then(response => {
            this.DataList = response.rows
              for (var i = 0; i < response.rows.length; i++) {
                // 渲染节点类型
                for (let j = 0; j < this.codeType.length; j++) {
                  if(response.rows[i].type == this.codeType[j].value) {
                    this.DataList[i].type = this.codeType[j].label
                  }
                }
              }
            this.total = response.total;
            this.loading = false;
            this.isnoClick = true;
          })
        },
        // 重置表单
        reset() {
          this.form = {
            type:undefined,//树节点
            parentId:undefined,//父节点
            name:[],//树节点名称
            remark:undefined,//备注
            orderNo:undefined,//排序
            codeName: undefined
          }
        },
        //添加树节点
        treehandleAdd (){
          this.reset();
          this.dialog.open0 = true
          this.dialog.title0 = "树节点"
          this.form.type = 't'
          this.isRefresh = false
        },
        // 添加全宗节点
        generalArchiveAdd() {
          var params = JSON.parse(JSON.stringify(this.queryParams))
          params.pageSize = 200
          listCode(params).then(res=>{
            getFondsByTenantCode().then(response => {
              this.dataOptions = response.data.map(option => {
                return {
                  value: option.id,
                  label: option.fondsName
                }
              })
              this.generalarchiveOpen = true
              this.isRefresh = false
              var arr = []
              for (let i = 0; i < res.rows.length; i++) {
                const data = this.dataOptions.filter(item => item.value == res.rows[i].fondsId)
                arr = arr.concat(data)
              }
              this.selectedOptions = arr
            })
          })
        },
        // 添加门类节点
        categoryAdd() {
          this.checkedKeys = []
          this.treeData = []
          const fondsId = this.queryParams.fondsId
          var params = JSON.parse(JSON.stringify(this.queryParams))
          params.pageSize = 200
          listCode(params).then(res=>{
            getcatebyfondsid(fondsId).then(response => {
              const rootNode = { id: 'root', label: '门类', children: [] };
              const otherNodes = response.data.map(option => {
                return {
                  id: option.id,
                  label: option.name
                }
              })
              rootNode.children = otherNodes;
              this.treeData.push(rootNode)
              var arr = []
              for (let i = 0; i < res.rows.length; i++) {
                const data = otherNodes.filter(item => item.id == res.rows[i].categoryId)
                arr = arr.concat(data)
              }
              for (let i = 0; i < arr.length; i++) {
                this.checkedKeys = this.checkedKeys.concat(arr[i].id)
              }
              this.$nextTick(() => {
                if (this.$refs.categoryTree) {
                  this.$refs.categoryTree.setCheckedKeys(this.checkedKeys)
                }
              });
              this.categoryOpen = true
              this.isRefresh = false
            })
          })
        },
        // 添加层级节点
        levelAdd() {
          const categoryId = this.queryParams.categoryId
          getCateType(categoryId).then(response => {
            console.log(response.data)
            if(response.data.type == "0") {
              this.LevelOptions = [
                { value: response.data.fileTableName, label: "件层", disabled: false },
                { value: response.data.efileTableName, label: "电子文件层", disabled: true }
              ]
            } else if(response.data.type == "1") {
              this.LevelOptions = [
                { value: response.data.folderTableName, label: "案卷层", disabled: false },
                { value: response.data.fileTableName, label: "件层", disabled: false },
                { value: response.data.efileTableName, label: "电子文件层", disabled: true }
              ]
            } else if(response.data.type == "3") {
              this.LevelOptions = [
                { value: response.data.itemTableName, label: "项目层", disabled: false },
                { value: response.data.folderTableName, label: "案卷层", disabled: false },
                { value: response.data.fileTableName, label: "件层", disabled: false },
                { value: response.data.efileTableName, label: "电子文件层", disabled: true }
              ]
            }
            var arr = []
            for (let i = 0; i < this.DataList.length; i++) {
              const data = this.LevelOptions.filter(item => item.value == this.DataList[i].subTableName)
              arr = arr.concat(data)
            }
            this.selectOption = arr
            this.LevelOpen = true
            this.isRefresh = false
          })
        },
        // 添加分类节点
        classificationAdd() {
          getData(this.queryParams.categoryId).then(response => {
            console.log(response.data.type)
            if(this.queryParams.type == "l") {
              this.form = {
                categoryId: this.queryParams.categoryId,
                level: this.level
              }
            } else {
              this.form = {
                categoryId: this.queryParams.categoryId,
                level: response.data.type
              }
            }
            getfl(this.form).then(response => {
              this.ClassificationOptions = response.data.datalist.map(option => {
                return {
                  id: option.FIELD_NAME,
                  label: option.FIELD_CAPTION,
                  value: option.value
                }
              })
              this.ClassificationOptions.push({
                id: 'ND',
                label: '年度'
              })
            })
            this.ndForm = {
              year: undefined,
              continuousTime: undefined
            }
            this.ClassificationOpen = true
            this.isRefresh = false
          })
        },
        // 根据勾选外层分类获取分类值
        handleOptionChange() {
          if(this.selected.value != null){
            this.valueOptions = this.selected.value.map(option => {
              return {
                value: option.dictValue,
                label: option.dictLabel,
                name: option.dictType
              }
            })
          } else {
            this.valueOptions = []
          }
          if(this.valueOptions.length != 0 || this.selected.id == 'ND'){
            this.isShowHr = true
          } else {
            this.isShowHr = false
          }
          var arr = []
          for (let i = 0; i < this.DataList.length; i++) {
            const data = this.valueOptions.filter(item => item.value == this.DataList[i].propertyValue && item.name == this.DataList[i].propertyName)
            arr = arr.concat(data)
          }
          this.valueSelected = arr
        },
        // 添加空节点
        emptyAdd() {
          this.reset();
          console.log(this.queryParams.parentId);
          if (this.queryParams.parentId==0){
            this.$modal.msgWarning("根节点下不能添加空节点");
            return;
          }
          /*console.log(this.queryParams.nodeId)
          console.log(this.queryParams.parentId)
          console.log(this.queryParams.type)*/
          this.dialog.open0 = true
          this.dialog.title0 = "空节点"
          this.form.type = 'n'
          this.isRefresh = false
        },
        // 修改节点
        handleUpdate() {
          this.reset();
          this.isRefresh = false
          const id = this.queryParams.nodeId
          if(this.queryParams.type == "t"){
            this.dialog.title0 = "树节点"
          } else if( this.queryParams.type == "n"){
            this.dialog.title0 = "空节点"
          } else if( this.queryParams.type == "f"){
            this.dialog.title0 = "全宗节点"
          } else if( this.queryParams.type == "a"){
            this.dialog.title0 = "门类节点"
          } else if( this.queryParams.type == "c"){
            this.dialog.title0 = "分类节点"
          } else if( this.queryParams.type == "l"){
            this.dialog.title0 = "层级节点"
          }
          getCode(id).then(response =>{
            this.form.codeName = response.data.name
            this.form.remark = response.data.remark
            this.form.orderNo = response.data.orderNo
            this.form.id = response.data.id
            this.dialog.open0 = true
          });
        },
        // 删除节点
        handleDelete() {
          this.isRefresh = false
          const id = this.queryParams.nodeId
          const label = this.queryParams.label
          this.$modal.confirm('是否确认删除节点名称为"' + label + '"的数据项？').then(function() {
            return delCode(id)
          }).then(() => {
            this.$modal.msgSuccess("删除成功");
            this.isRefresh = true
            this.getList();
          }).catch(() => {});
        },
        // 树节点弹窗关闭
        cancel() {
          this.dialog.open0 = false
        },
        // 保存操作
        submitForm() {
          this.$refs["form"].validate((valid) => {
            if (valid) {
              if(this.form.id != undefined) {
                this.form.name = this.form.codeName
                updateCode(this.form).then(response => {
                  this.$modal.msgSuccess("修改成功");
                  this.dialog.open0 = false;
                  this.isRefresh = true
                  this.getList();
                })
              } else {
                const arr = this.form.codeName.split()
                this.form.name = arr
                this.form.parentId = this.queryParams.parentId
                addCode(this.form).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.dialog.open0 = false;
                  this.isRefresh = true
                  this.getList();
                });
              }
            }
          })
        },
        // 全宗保存
        submitGeneralarchive() {
          if(this.selectedOptions.length == 0) {
            this.$message({ message: '请选择至少一个全宗节点!', type: 'warning' })
          } else {
            this.reset()
            this.form.type = "f"
            this.form.parentId = this.queryParams.parentId
            var arr = []
            for (let i = 0; i < this.selectedOptions.length; i++) {
              this.form.name.push(this.selectedOptions[i].label)
              arr.push(this.selectedOptions[i].value)
            }
            this.form.fondsId = arr
            addCode(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.generalarchiveOpen = false;
              this.isRefresh = true
              this.getList();
            });
          }
        },
        // 门类保存
        submitCategory() {
          const tree = this.$refs.categoryTree;
          const checkedNodes = tree.getCheckedNodes();
          // 过滤掉根节点
          const filteredNodes = checkedNodes.filter(node => node.id != 'root');
          if(filteredNodes.length == 0){
            this.$message({ message: '请选择至少一个除门类树根节点外的节点!!', type: 'warning' })
          } else {
            this.reset()
            this.form.type = "a"
            this.form.parentId = this.queryParams.parentId
            var arr = []
            for(let i=0;i<filteredNodes.length;i++){
              this.form.name.push(filteredNodes[i].label)
              arr.push(filteredNodes[i].id)
            }
            this.form.categoryId = arr
            addCode(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.categoryOpen = false;
              this.isRefresh = true
              this.getList();
            });
          }
        },
        categoryCancel() {
            this.categoryOpen = false
        },
        // 层级保存
        submitLevel() {
          if(this.selectOption.length == 0) {
            this.$message({ message: '请选择至少一个层级节点!', type: 'warning' })
          } else {
            this.reset()
            this.form.type = "l"
            this.form.parentId = this.queryParams.parentId
            var arr = []
            for (let i = 0; i < this.selectOption.length; i++) {
              this.form.name.push(this.selectOption[i].label)
              arr.push(this.selectOption[i].value)
            }
            this.form.subTableName = arr
            addCode(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.LevelOpen = false;
              this.isRefresh = true
              this.getList();
            });
            this.selectedOptions = []
          }
        },
        // 分类保存
        submitClassification() {
          if(this.selected.length == 0){
            this.$message({ message: '请选择分类!', type: 'warning' })
          } else {
            if (this.selected.id == 'ND') {
              this.$refs.ndForm.validate((valid) => {
                if(valid) {
                  this.reset()
                  this.form = {
                    type: "c",
                    parentId: this.queryParams.parentId,
                    name: this.ndForm.year.split(','),
                    propertyName: this.selected.id,
                    propertyValue: this.ndForm.continuousTime.toString().split(',')
                  }
                  addCode(this.form).then(response => {
                    this.$modal.msgSuccess("新增成功");
                    this.ClassificationOpen = false;
                    this.isRefresh = true
                    this.getList();
                  })
                  this.valueSelected = []
                  this.selected = []
                  this.isShowHr = false
                  this.ndForm = {
                    year: undefined,
                    continuousTime: undefined
                  }
                }
              })
            } else {
              if(this.valueSelected.length == 0) {
                this.$message({ message: '请选择分类节点中的属性!', type: 'warning' })
              } else {
                this.reset()
                this.form.type = "c"
                this.form.parentId = this.queryParams.parentId
                var arr = []
                for (let i = 0; i < this.valueSelected.length; i++) {
                  this.form.name.push(this.valueSelected[i].label)
                  arr.push(this.valueSelected[i].value)
                }
                this.form.propertyValue = arr
                this.form.propertyName = this.selected.id
                addCode(this.form).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.ClassificationOpen = false;
                  this.isRefresh = true
                  this.getList();
                });
                this.valueSelected = []
                this.selected = []
                this.isShowHr = false
              }
            }
          }
        },
        ClassificationCancel() {
          this.ClassificationOpen = false
          this.valueSelected = []
          this.selected = []
          this.isShowHr = false
        },
    }
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% - 30px);
  max-width: calc(100% - 30px);
}

::v-deep .el-dialog .el-dialog__body {
  flex: 1;
  overflow: auto;
}
</style>
